// 定义验证规则

// 需要先添加joi 以及 @escook/express-joi依赖

// 导入定义验证规则的包
const joi = require('joi')

const username = joi.string().alphanum().min(6).max(12).required()

const password = joi.string().pattern(/^[\S]{6,12}/).required()
// joi.ref('password')
// 手机号码
const telephoneNum = joi.number().integer().min(11)
// 旧密码
const oldpassword = password
//新密码
// @ts-ignore
const newpassword = joi.not(joi.ref('oldpassword')).concat(password)
//头像
const avater = joi.string().dataUri().required()
const email = joi.string().email()


// 定义用户登录注册的验证规则对象
exports.user_schema = {
    body: {
        username,
        password
    },
    params: {},
    query: {}
}

//定义用户修改信息的验证规则对象
exports.update_userSchema = {
    body: {
        phone: telephoneNum,
        email
    }
}

// 定义用户修改密码的对象
exports.update_passwordSchema = {
    body: {
        oldpassword,
        newpassword
    }
}

//定义头像验证头像
exports.update_avater = {
    body: {
        avater
    }
}